from sklearn import datasets
import torch
import numpy as np
def PCA(X,k=2):

    X_mean=torch.mean(X,0)
    X=X-X_mean.expand_as(X)
    U,S,V=torch.svd(torch.t(X))
    return torch.mm(X,U[:,:,k])

iris=datasets.load_iris()
X=torch.from_numpy(iris.data)
y=iris.target
X_PCA=PCA(X)
pca=X_PCA.numpy()